package com.zf.shuashua.ui.follow;

import androidx.lifecycle.LiveData;
import androidx.lifecycle.MutableLiveData;
import androidx.lifecycle.ViewModel;

import com.vise.xsnow.http.callback.ACallback;
import com.zf.shuashua.api.HttpData;
import com.zf.shuashua.bean.BaseListData;
import com.zf.shuashua.bean.VideoInfo;

public class FollowViewModel extends ViewModel {

    private MutableLiveData<String> mText;
    private MutableLiveData<BaseListData<VideoInfo>> mVideoDataRefresh;
    private MutableLiveData<BaseListData<VideoInfo>> mVideoDataLoadMore;

    public FollowViewModel() {
        mText = new MutableLiveData<>();
        mText.setValue("This is dashboard fragment");
    }

    public LiveData<String> getText() {
        return mText;
    }

    public MutableLiveData<BaseListData<VideoInfo>> getFollowVideoDataRefresh() {
        if (mVideoDataRefresh == null) {
            mVideoDataRefresh = new MutableLiveData<>();
        }
        return mVideoDataRefresh;
    }

    public MutableLiveData<BaseListData<VideoInfo>> getFollowVideoDataLoadMore() {
        if (mVideoDataLoadMore == null) {
            mVideoDataLoadMore = new MutableLiveData<>();
        }
        return mVideoDataLoadMore;
    }

    public void fetchFollowDataRefresh(int page) {
        HttpData.getInstance().getFollowVideo(page, new ACallback<BaseListData<VideoInfo>>() {
            @Override
            public void onSuccess(BaseListData<VideoInfo> data) {
                getFollowVideoDataRefresh().setValue(data);
            }

            @Override
            public void onFail(int errCode, String errMsg) {
                getFollowVideoDataRefresh().setValue(null);
            }
        });
    }

    public void fetchFollowDataLoadMore(int page) {
        HttpData.getInstance().getFollowVideo(page, new ACallback<BaseListData<VideoInfo>>() {
            @Override
            public void onSuccess(BaseListData<VideoInfo> data) {
                getFollowVideoDataLoadMore().setValue(data);
            }

            @Override
            public void onFail(int errCode, String errMsg) {
                getFollowVideoDataLoadMore().setValue(null);
            }
        });
    }
}